/*
 * Copyright (c) 2025 Industrial Software Feature Database
 */
package com.comac.ins.test;

import com.comac.ins.isfd.domain.IsfdMeshOp2CompareResultData;
import com.comac.ins.isfd.domain.bo.IsfdMeshOp2InfoBo;
import com.comac.ins.isfd.domain.bo.IsfdMeshOp2QueryBo;
import com.comac.ins.isfd.service.IIsfdMeshOP2ParseService;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.IntStream;


@SpringBootTest
public class IsfdMeshOP2ParseServiceImplTest {
    @Autowired
    private IIsfdMeshOP2ParseService isfdMeshOP2ParseService;

    private static final String TEST_OBJECT_ID = "67ee38d0445e661dc1b0b782";
    private static final String TEST_UPLOAD_ID = "67ee38d0445e661dc1b0b782";

    @BeforeAll
    static void setup() {
        System.out.println("初始化测试环境...");
    }

    @Test
    @Order(1)
    public void testParseAndSaveOP2() {
        // **1. 提供真实的 .op2 文件路径**
//        String FILE_FOLDER = "C:\\Users\\lijpt\\OneDrive\\Documents\\COMAC\\ISFD\\结果库\\op2\\";
//        FILE_FOLDER = "D:\\结果文件\\计算结果\\计算结果\\";
//        String FILE_NAME = "cr929_r1_pressure_wf_fatigue_middle_20240506052458A016.op2";
//        FILE_NAME = "ht-平尾升降舵及后缘\\cac_ele_001.op2";
//        String filePath = FILE_FOLDER + FILE_NAME;  // 请替换为真实路径
        String FILE_FOLDER = "C:\\Users\\lijpt\\OneDrive\\Documents\\COMAC\\ISFD\\结果库\\改造\\";
        String FILE_NAME = "aircraft.h5";
        String filePath = FILE_FOLDER + FILE_NAME;
        String fileHash = "test_hash";

        // **2. 构造测试数据**
        IsfdMeshOp2InfoBo mockInfoVo = new IsfdMeshOp2InfoBo();
        mockInfoVo.setObjectId(TEST_OBJECT_ID);
        mockInfoVo.setUploadId(TEST_UPLOAD_ID);
        mockInfoVo.setFilePath(filePath);
        mockInfoVo.setFileHash(fileHash);

        // **3. 调用实际方法解析并存储**
        isfdMeshOP2ParseService.parseAndSaveResultByType(mockInfoVo);
    }

    @Test
    @Order(2)
    public void testFindOP2() {
        // **1. 提供真实的 .op2 文件路径**
        String COLLECTION_NAME = "01af6dfc-600a-4c06-a0b3-a0e37db34448";
        String RESULT_NAME = "force.cbar_force";
        String SUB_RESULT_NAME = "axial";

        int startIndex = 71140400;
        Map<Integer, Integer> elementIds = IntStream.rangeClosed(startIndex, startIndex+100)
            .boxed()
            .collect(Collectors.toMap(
                i -> i - startIndex + 1, // key 从 1 开始
                i -> i
            ));

        // **2. 构造测试数据**
        IsfdMeshOp2QueryBo queryBo = new IsfdMeshOp2QueryBo();
        queryBo.setCollectionName(COLLECTION_NAME);
        queryBo.setElementPairs(elementIds);
        queryBo.setResultName(RESULT_NAME);
        queryBo.setUploadId(COLLECTION_NAME);
        queryBo.setSubResultName(SUB_RESULT_NAME);

        // **3. 调用实际方法解析并存储**
        IsfdMeshOp2CompareResultData data = isfdMeshOP2ParseService.getResultData(queryBo);

        System.out.println("finished");
    }

    @AfterAll
    static void cleanup() {
        System.out.println("清理测试环境...");
    }
}
